package ArrayAddSubtract;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @Author MDD
 * @Description
 * @Version
 * @Date
 **/
public class ArrayModify {
    public static void main(String[] args) {
        String[] names = {"Tom","Sam","Jack","Alice","Ruby","Robin"};
        Scanner sc = new Scanner(System.in);
        System.out.print("请输入想修改的原英文名：");
        String name = sc.next();
        System.out.print("请输入新英文名字：");
        String newname = sc.next();
        int j = -1;
        for (int i = 0; i < names.length; i++) {
            if (name.equalsIgnoreCase(names[i])){
                j= i;
                break;
            }
        }
        System.out.println("j="+j);
        if (j!=-1){
            for (int i = j; i < names.length-1; i++) {
                names[j] =  newname;
            }
            System.out.println(Arrays.toString(names));
            names[names.length-1] = null;
        }
        else {
            System.out.println("没有该名字");
        }
        System.out.println("打印名字：");
        for (String item:names) {
            System.out.print(item+"\t");
        }
    }
}
